// pages/mine/evaluate/to_evaluate.js
var app = getApp(), u = app.require("utils/util.js"), a = app.require("utils/api.js"), o = app.require("utils/onfire.js"), h = app.require("utils/http.js"), n = app.require("utils/enums");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    remarkInputFocus: !1,
    goodslist: {},
    order_no: '',
    order_id:'',
    uid: '',
    isstatus: false
  },
  onLoad: function (options) {
    this.data.order_no = options.order_no;
    this.data.uid = wx.getStorageSync('userInfo')['uid'];
    this.getProductInfo();
  },
  getProductInfo: function () {
    var t = this;
    var data = { store_id: a.storeId, uid: t.data.uid, order_no: t.data.order_no }
    h.postReq(a.orderdetails, data, function (res) {
      if (res.code === 0) {
        let goodslist = [];
        for (let i = 0; i < res.data.product_list.length; i++) {
          goodslist[i] = res.data.product_list[i];
          goodslist[i]['starts'] = 5;
          goodslist[i]['evaluatestartname'] = "非常满意";
          goodslist[i]['evaluatescontent'] = "";
          goodslist[i]['contentlength'] = 1000;
          goodslist[i]['invisible'] = false;
        }
        t.setData({
          goodslist: goodslist,
          order_id: res.data.order.order_id,
        });
      }

      console.log(res);
    });
  }, onRemarkConfirm: function (e) {
    var t = this;
    if (e.detail.value.length > 10) {
      t.data.goodslist[e.target.dataset.id].contentlength = 1000 - (e.detail.value.length > 0 ? e.detail.value.length : 0);
      t.setData({
        goodslist: t.data.goodslist,
      });
    }

  },
  evaluateClick: function (e) {
    var t = this;
    t.data.goodslist[e.target.dataset.id].starts = e.detail.value;
    switch (t.data.goodslist[e.target.dataset.id].starts) {
      case 1:
        t.data.goodslist[e.target.dataset.id].evaluatestartname = "非常差";
        break;
      case 2:
        t.data.goodslist[e.target.dataset.id].evaluatestartname = "差";
        break;
      case 3:
        t.data.goodslist[e.target.dataset.id].evaluatestartname = "一般";
        break;
      case 4:
        t.data.goodslist[e.target.dataset.id].evaluatestartname = "满意";
        break;
      case 5:
        t.data.goodslist[e.target.dataset.id].evaluatestartname = "非常棒";
        break;

    }
    t.setData({
      goodslist: t.data.goodslist,
    });

  },
  onSubmit: function (e) {
    let t = this;
    let fromdata = e.detail.value;
    let goodsevaluate = [];
    for (let i = 0; i < t.data.goodslist.length; i++) {
      goodsevaluate.push({
         'content': fromdata['content['+i+']'],
         'pid': t.data.goodslist[i]['pigcms_id'],
         'relation_id': t.data.goodslist[i]['product_id'],
         'score': t.data.goodslist[i]['starts'],
        'is_show_username': fromdata['showname[' + i + ']'],
         'images_id_str':[],
         'tag_id_str':[],
         });
    }

    let data = {
      "order_id": t.data.order_id,
      "product_data": goodsevaluate,
      "store_data":{}
    }
    h.postReq(a.getUserOrderCommentUrl, data, function (res) {
      if (res.code == 0) {
        u.success('评论成功', function () {
          wx.navigateTo({
            url: 'evaluate',
          })
        });
      }
    });

  },
  handlerRate: function (e) {
    console.log(e);
  }
})